Skip to content

Conversation

@ye-luo
Copy link
Contributor

@ye-luo ye-luo commented Jan 28, 2026

Proposed changes

Currently, nexus executables require a closely coupled nexus modules, namely

<nexus_root>/bin # contains nexus exectuables
<nexus_root>/nexus #contains nexus module files

find_nexus_module honors this layout and verifies nexus module import.
qmca has the gold implementation and other scripts follow.

I also corrected the following discovery path.

nexus_lib = os.path.realpath(os.path.join(__file__,'..','..','..','nexus'))

nexus internal lookup should not go beyond <nexus_root>. Simply use

nexus_lib = os.path.realpath(os.path.join(__file__,'..','..'))

What type(s) of changes does this code introduce?

  • Refactoring (no functional changes, no api changes)
  • Other (please describe): more error traps

Does this introduce a breaking change?

  • No

What systems has this change been tested on?

laptop

Checklist

    • I have read the pull request guidance and develop docs
    • This PR is up to date with the current state of 'develop'
    • Code added or changed in the PR has been clang-formatted
    • This PR adds tests to cover any new code, or to catch a bug that is being fixed
    • Documentation has been added (if appropriate)

@ye-luo
Copy link
Contributor Author

ye-luo commented Jan 28, 2026

Test this please

Copy link
Contributor

@brockdyer03 brockdyer03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As best I can tell, while this code does unify the find_nexus_modules function, it doesn't do anything to stop enforcement of the location of the executables being with the rest of Nexus. Perhaps a separate bit of code that checks if you're in a QMCPACK install directory would fix it?

nexus_lib2 = os.path.realpath(os.path.join(nexus.__file__,'..','..'))

# ensure closely coupled nexus module is in use.
if nexus_lib != nexus_lib2:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the line that is probably going to continue failing if the executables get moved. The enforcement of location of the current file with the location of Nexus means that this will likely still result in a failure if the executables are moved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately that is a current requirement.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the strict association in this PR. We can remove it in a following PR once a decision is made.

@ye-luo ye-luo marked this pull request as draft January 29, 2026 00:45
@ye-luo
Copy link
Contributor Author

ye-luo commented Jan 29, 2026

The introduced nexus_modules.py generate __pycache__ and prevents executing nexus/install.

execute('cp {0}/bin/* {1}'.format(source_dir,install_dir))

err: b"cp: -r not specified; omitting directory '/home/yeluo/opt/qmcpack/nexus/bin/__pycache__'\n"

@ye-luo ye-luo force-pushed the consolidate-nexus-executables branch 2 times, most recently from 149eedb to 5d9f62e Compare January 29, 2026 01:18
@brockdyer03
Copy link
Contributor

To be honest I forgot about __pycache__. That gets created whenever you import Python modules that are not your current module. Usually that only gets made in qmcpack/nexus/nexus, but since there was a .py file added to qmcpack/nexus/bin it'll make one if you run anything before doing the copy. I don't think that creating a separate .py file is a viable option.

I think since @jtkrogel said he was fine with most of the executables not actually enforcing association with the rest of Nexus (except for nxs-test) it would probably be fine to just delete find_nexus_modules from all of the files (again, except for nxs-test) and put the onus on the user to ensure their Python path is set properly.

@ye-luo ye-luo force-pushed the consolidate-nexus-executables branch from 5d9f62e to 0441e82 Compare January 29, 2026 04:17
@ye-luo
Copy link
Contributor Author

ye-luo commented Jan 29, 2026

To be honest I forgot about __pycache__. That gets created whenever you import Python modules that are not your current module. Usually that only gets made in qmcpack/nexus/nexus, but since there was a .py file added to qmcpack/nexus/bin it'll make one if you run anything before doing the copy.

You analysis is correct

I don't think that creating a separate .py file is a viable option.

simply avoid files starting with underscore. taken care by #5768

I think since @jtkrogel said he was fine with most of the executables not actually enforcing association with the rest of Nexus (except for nxs-test) it would probably be fine to just delete find_nexus_modules from all of the files (again, except for nxs-test) and put the onus on the user to ensure their Python path is set properly.

I actually prefer all the nexus executable runnable without setting PYTHONPATH by the user or by a virtual environment. They must be exactly matched to the nexus module in the same git commit. The current strict coupling requirement made nexus executables invulnerable to hidden PYTHONPATH changes.

@ye-luo ye-luo marked this pull request as ready for review January 29, 2026 04:41
@jtkrogel
Copy link
Contributor

Need to catch up with the discussion here. From what I understand of our prior discussion, no decisions had been made about enforcing strict association between the binaries and nexus modules (though I favor retaining it).

@jtkrogel
Copy link
Contributor

On a closer look, I really don't see the virtue of including a non-binary (find_nexus_modules.py) in the binaries directory. I can understand the desire to remove all instances of code duplication, but I think the unwieldiness of this change is worse.

@brockdyer03
Copy link
Contributor

simply avoid files starting with underscore. taken care by #5768

I think this could potentially introduce unwanted side effects. For example, qmcpack/nexus/nexus has a file __init__.py which was renamed from nexus.py to be compliant with packaging guidelines. Without that file, the entire package will stop working, so if that copy script ever gets duplicated it will cause significant errors that will be hard to trace.

Copy link
Contributor

@prckent prckent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nexus/bin is for directly shell executable programs; putting a not directly callable function there is non-standard and will confuse users (etc.). Could it be made a verify_nexus_installation utility that can also be called directly? If this route works, we could expand it subsequently to include a reporting of the various nexus required and optional package imports.

@ye-luo ye-luo changed the title Introduce nexus_modules to handle consistent nexus module searching by nexus exectuables Refine find_nexus_module search locations and error handling Jan 29, 2026
@ye-luo ye-luo force-pushed the consolidate-nexus-executables branch from 4657b08 to 139fac4 Compare January 29, 2026 18:51
@ye-luo
Copy link
Contributor Author

ye-luo commented Jan 29, 2026

@prckent verify_nexus_installation has been introduced. I couldn't find a clean way to avoid code duplication. Using sub-process to invoke verify_nexus_installation is still very messy. So just copied find_nexus_module into each script noting that the reference copy is from verify_nexus_installation

@ye-luo ye-luo force-pushed the consolidate-nexus-executables branch from 139fac4 to 5eec27e Compare January 29, 2026 18:55
@ye-luo ye-luo force-pushed the consolidate-nexus-executables branch from 5eec27e to 646ad70 Compare January 29, 2026 19:01
@ye-luo ye-luo added this to the v4.2.0 Release milestone Jan 29, 2026
@jtkrogel
Copy link
Contributor

jtkrogel commented Feb 2, 2026

It is the job of nxs-test to validate the installation, so having verify_nexus_installation is redundant and misleading (it verifies nothing but paths while the installation could still be broken). The "gold" implementation of the path checking should reside in nxs-test.

nexus_lib2 = os.path.realpath(os.path.join(nexus.__file__,'..','..'))

# ensure closely coupled nexus module is in use.
if nexus_lib != nexus_lib2:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the strict association in this PR. We can remove it in a following PR once a decision is made.

from time import time # used to get user wall clock rather than cpu time
tstart_all = time()

testing_wrong_nexus_install = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this deleted?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reply. This should not be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The replaced find_nexus_module did the work already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the current requirement of nxs-test that exception should not be raise by itself. The gold implementation can not be used and kept by nxs-test. I reverted most of the changes in nxs-test.

@@ -0,0 +1,38 @@
#! /usr/bin/env python3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be removed. See comment in the conversation/chat.

@ye-luo
Copy link
Contributor Author

ye-luo commented Feb 2, 2026

It is the job of nxs-test to validate the installation, so having verify_nexus_installation is redundant and misleading (it verifies nothing but paths while the installation could still be broken). The "gold" implementation of the path checking should reside in nxs-test.

Currently nxs-test needs extra work to have a proper installation. Consider the added tool a stopgap utility.

@ye-luo
Copy link
Contributor Author

ye-luo commented Feb 3, 2026

@prckent I removed verify_nexus_Installation that @jtkrogel considered redundant and we had a hard time to agree on what exactly it should serve and where it should be hosted. The same check exists in every nexus binary should be sufficient to catch the issue and inform users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants